{include file="public/header" /}

<body style="background-color: #ffffff">
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">
                <div class="layui-form-item">
                    <label for="L_choose_name" class="layui-form-label">
                        <span class="x-red">*</span>交易币种</label>
                    <div class="layui-input-inline">
                        <select name="coin" lay-verify="required" lay-filter="term">
                            {if empty($row.coin)}<option value="0">请选择币种</option>{/if}
                            {foreach $coin as $k => $v}
                            <option value="{$k}" {if !empty($row.coin) && $row.coin==$k}selected{/if}>{$v}
                            </option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_choose_name" class="layui-form-label">
                        <span class="x-red">*</span>市场币种</label>
                    <div class="layui-input-inline">
                        <select name="mart" lay-verify="required" lay-filter="term">
                            {if empty($row.mart)}<option value="0">请选择币种</option>{/if}
                            {foreach $mart as $k => $v}
                            <option value="{$k}" {if !empty($row.mart) && $row.mart==$k}selected{/if}>{$v}
                            </option>
                            {/foreach}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_choose_name" class="layui-form-label">
                        <span class="x-red">*</span>是否交易</label>
                    <div class="layui-input-inline">
                        <select name="istrans" lay-verify="required" lay-filter="term">
                            <option value="1" {if !empty($row.istrans) && $row.istrans==1}selected{/if}>是</option>
                            <option value="2" {if !empty($row.istrans) && $row.istrans==2}selected{/if}>否</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_choose_name" class="layui-form-label">
                        <span class="x-red">*</span>是否显示行情</label>
                    <div class="layui-input-inline">
                        <select name="ishow" lay-verify="required" lay-filter="term">
                            <option value="1" {if !empty($row.ishow) && $row.ishow==1}selected{/if}>是</option>
                            <option value="2" {if !empty($row.ishow) && $row.ishow==2}selected{/if}>否</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_choose_name" class="layui-form-label">
                        <span class="x-red">*</span>买入手续费</label>
                    <div class="layui-input-inline">
                        <input type="number" id="buyhand" name="buyhand" required="" lay-verify="required"
                            autocomplete="off" class="layui-input" value="{$row.buyhand|default='0'}" placeholder="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_choose_name" class="layui-form-label">
                        <span class="x-red">*</span>卖出手续费</label>
                    <div class="layui-input-inline">
                        <input type="number" id="sellhand" name="sellhand" required="" lay-verify="required"
                            autocomplete="off" class="layui-input" value="{$row.sellhand|default='0'}" placeholder="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_choose_name" class="layui-form-label">
                        <span class="x-red">*</span>币种全称</label>
                    <div class="layui-input-inline">
                        <input type="text" id="name" name="name" required="" lay-verify="required" autocomplete="off"
                            class="layui-input" value="{$row.name|default=''}" placeholder="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="cover" class="layui-form-label">
                        <span class="x-red">*</span>币种LOGO</label>
                    <div class="layui-input-inline">
                        <button type="button" class="layui-btn" id="test1">上传图片</button>
                        <div class="layui-upload-list">
                            <input type="hidden" value="{$row.logos|default=''}" name="logos" id="cover">
                            <img class="layui-upload-img" id="demo1" src="{$row.logos|default=''}"
                                style="width: 200px;height: auto;">
                            <p id="demoText"></p>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_choose_name" class="layui-form-label">
                        <span class="x-red">*</span>发行时间</label>
                    <div class="layui-input-inline">
                        <input type="text" id="pubdate" name="pubdate" required="" lay-verify="required"
                            autocomplete="off" class="layui-input" value="{$row.pubdate|default=''}" placeholder="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_choose_name" class="layui-form-label">
                        <span class="x-red">*</span>发行总量</label>
                    <div class="layui-input-inline">
                        <input type="number" id="pubtotal" name="pubtotal" required="" lay-verify="required"
                            autocomplete="off" class="layui-input" value="{$row.pubtotal|default='0'}" placeholder="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_choose_name" class="layui-form-label">
                        <span class="x-red">*</span>流通总量</label>
                    <div class="layui-input-inline">
                        <input type="number" id="currtotal" name="currtotal" required="" lay-verify="required"
                            autocomplete="off" class="layui-input" value="{$row.currtotal|default='0'}" placeholder="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_choose_name" class="layui-form-label">
                        <span class="x-red">*</span>众筹价格</label>
                    <div class="layui-input-inline">
                        <input type="number" id="crowdprice" name="crowdprice" required="" lay-verify="required"
                            autocomplete="off" class="layui-input" value="{$row.crowdprice|default='0'}" placeholder="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_choose_name" class="layui-form-label">
                       白皮书</label>
                    <div class="layui-input-inline">
                        <input type="text" id="whitepaper" name="whitepaper" 
                            autocomplete="off" class="layui-input" value="{$row.whitepaper|default=''}" placeholder="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_choose_name" class="layui-form-label">
                       官网</label>
                    <div class="layui-input-inline">
                        <input type="text" id="website" name="website" 
                            autocomplete="off" class="layui-input" value="{$row.website|default=''}" placeholder="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_choose_name" class="layui-form-label">
                       区块查询地址</label>
                    <div class="layui-input-inline">
                        <input type="text" id="blockqurey" name="blockqurey" 
                            autocomplete="off" class="layui-input" value="{$row.blockqurey|default=''}" placeholder="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="layeditDemo" class="layui-form-label">
                        项目介绍</label>
                    <div class="layui-input-inline" style="width: 60%;">
                        <textarea id="intro"
                            name="info">{if !empty($row.info)}{:htmlspecialchars_decode($row.info)}{/if}</textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <input type="hidden" value="{$row.id|default=''}" name="id">
                    <button class="layui-btn" lay-filter="add" lay-submit="">提交</button>
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <button type="button" class="layui-btn layui-btn-primary" onclick="IframeClose()">取消</button>

                </div>
            </form>
        </div>
    </div>

    {include file="public/footer" /}
    <script src="/static/leyedit/Layui-KnifeZ/layui.js"></script>
    <script src="/static/leyedit/ace/ace.js"></script>
    <script>
        layui.use(['upload','laydate'], function () {
            var $ = layui.jquery
            , laydate = layui.laydate
                , upload = layui.upload;
            //图片上传
            laydate.render({
                elem: '#pubdate' //指定元素
            });
            var uploadInst = upload.render({
                elem: '#test1'
                , url: '/Base/upload_img'
                , accept: 'images'
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#demo1').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code > 0) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    $('#cover').val(res.data.src);
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });
        });
        layui.use(['layedit', 'layer', 'jquery', 'form'], function () {
            $ = layui.jquery;
            var form = layui.form
                , layer = layui.layer;
            var layedit = layui.layedit;

            layedit.set({
                //暴露layupload参数设置接口 --详细查看layupload参数说明
                uploadImage: {
                    url: '/Base/upload_img',
                    accept: 'image',
                    acceptMime: 'image/*',
                    exts: 'jpg|png|gif|bmp|jpeg',
                    size: '100240'
                }
                //右键删除图片/视频时的回调参数，post到后台删除服务器文件等操作，
                //传递参数：
                //图片： imgpath --图片路径
                //视频： filepath --视频路径 imgpath --封面路径
                , calldel: {
                    url: '/Base/upload_img'
                }
                //开发者模式 --默认为false
                , devmode: false
                //插入代码设置
                , codeConfig: {
                    hide: true,  //是否显示编码语言选择框
                    default: 'javascript' //hide为true时的默认语言格式
                }
                , tool: ['strong', 'italic', 'underline', 'del', 'addhr', '|', 'fontFomatt', 'colorpicker', 'face'
                    , '|', 'left', 'center', 'right', '|', 'link', 'unlink', 'images', 'image_alt', 'anchors'
                    , '|', 'table', 'fullScreen'
                ]
                , height: '300px'
            });
            var intro = layedit.build('intro');
            //监听提交
            form.on('submit(add)', function (data) {
                data.field.info = layedit.getContent(intro);
                //发异步，把数据提交给php
                $.ajax({
                    'type': 'post',
                    data: data.field,
                    success: function (res) {
                        console.log(res);
                        if (res.status == 0) {
                            layer.msg(res.msg, { icon: 6, time: 1000 }, function () {
                                // 获得frame索引
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.location.reload();
                                parent.layer.close(index);
                            });
                        } else {
                            layer.msg(res.msg, { icon: 2, time: 1000 });
                        }
                    }
                });
                return false;
            });
        });
    </script>

</body>

</html>